package Service

import SQL.DatabaseHelper
import android.content.Context
import android.database.Cursor

class LoginService(private val context: Context) {
    fun login(username: String, password: String): Boolean {
        val databaseHelper = DatabaseHelper(context)
        val db = databaseHelper.readableDatabase

        val selection = "${DatabaseHelper.COLUMN_USERNAME} =? AND ${DatabaseHelper.COLUMN_PASSWORD} =?"
        val selectionArgs = arrayOf(username, password)

        val cursor: Cursor? = db.query(
            DatabaseHelper.TABLE_NAME,
            null,
            selection,
            selectionArgs,
            null,
            null,
            null
        )

        val result = cursor?.count?: 0 > 0

        cursor?.close()
        db.close()
        databaseHelper.close()

        return result
    }
}